import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class AddressService extends BaseService<any> {
  private readonly logger = new Logger(AddressService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getList
   * 对应 PHP: AddressService_admin::getList()
   * 逻辑类型: undefined - undefined
   */
  async getList(where: any[]) {
    // 基于PHP真实逻辑: getList
    // PHP原文: $where['site_id'] = $this->site_id;         return ( new CoreMemberAddressService() )->getList($where);     }      /**      * 获取会员收货地址信息      * @param...
where.site_id = this.site_id;
        return ( this.coreMemberAddressService ).getList(where);
    }

    /**
     * 获取会员收货地址信息
     * @param int id
     * @param data
     * @return */
    async getInfo(id, data)
    {
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).getInfo(id, data);
    }

    /**
     * 添加会员收货地址
     * @param data
     * @return mixed
     */
    async add(data)
    {
        const analysis_res = ( this.areaService ).getAddress(data.full_address);
        if (analysis_res.status == 0 && analysis_res.message == 'Success' && !!analysis_res.result))  {
            data.lng = analysis_res.result.location.lng;
            data.lat = analysis_res.result.location.lat;
  }

  /**
   * getInfo
   * 对应 PHP: AddressService_admin::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(id: any, data: any) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $data['site_id'] = $this->site_id;         return ( new CoreMemberAddressService() )->getInfo($id, $data);     }      /**      * 添加会员收货地址      * @para...
data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).getInfo(id, data);
    }

    /**
     * 添加会员收货地址
     * @param data
     * @return mixed
     */
    async add(data)
    {
        const analysis_res = ( this.areaService ).getAddress(data.full_address);
        if (analysis_res.status == 0 && analysis_res.message == 'Success' && !!analysis_res.result))  {
            data.lng = analysis_res.result.location.lng;
            data.lat = analysis_res.result.location.lat;
  }

  /**
   * add
   * 对应 PHP: AddressService_admin::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $analysis_res = ( new AreaService() )->getAddress($data['full_address']);         if ($analysis_res['status'] == 0 && $analysis_res['message'] == 'Suc...
const analysis_res = ( this.areaService ).getAddress(data.full_address);
        if (analysis_res.status == 0 && analysis_res.message == 'Success' && !!analysis_res.result))  {
            data.lng = analysis_res.result.location.lng;
            data.lat = analysis_res.result.location.lat;
  }

  /**
   * edit
   * 对应 PHP: AddressService_admin::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(id: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $analysis_res = ( new AreaService() )->getAddress($data['full_address']);         if ($analysis_res['status'] == 0 && $analysis_res['message'] == 'Suc...
const analysis_res = ( this.areaService ).getAddress(data.full_address);
        if (analysis_res.status == 0 && analysis_res.message == 'Success' && !!analysis_res.result))  {
            data.lng = analysis_res.result.location.lng;
            data.lat = analysis_res.result.location.lat;
  }
}
